<template>
  <div>
    <el-dialog
      v-model="store.state.HomeModule.dialogFormVisible"
      title="修改车位信息"
    >
      <el-form :model="form">
        <el-form-item label="车牌号码" :label-width="formLabelWidth">
          <el-input
            v-model="form.plate"
            autocomplete="off"
            :placeholder="form.plate"
          />
        </el-form-item>
        <el-form-item label="车主姓名" :label-width="formLabelWidth">
          <el-input
            v-model="form.name"
            autocomplete="off"
            :placeholder="form.name"
          />
        </el-form-item>
        <el-form-item label="车主住所" :label-width="formLabelWidth">
          <el-input
            v-model="form.residence"
            autocomplete="off"
            :placeholder="form.residence"
          />
        </el-form-item>
        <el-form-item label="汽车品牌" :label-width="formLabelWidth">
          <el-input
            v-model="form.brand"
            autocomplete="off"
            :placeholder="form.brand"
          />
        </el-form-item>
        <el-form-item label="汽车型号" :label-width="formLabelWidth">
          <el-input
            v-model="form.model"
            autocomplete="off"
            :placeholder="form.model"
          />
        </el-form-item>
        <el-form-item label="停车场位置号" :label-width="formLabelWidth">
          <el-input
            v-model="form.number"
            autocomplete="off"
            :placeholder="form.number"
          />
        </el-form-item>

        <el-form-item label="购车地点" :label-width="formLabelWidth">
          <el-input
            v-model="form.purchase"
            autocomplete="off"
            :placeholder="form.purchase"
          />
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input
            v-model="form.remarks"
            autocomplete="off"
            :placeholder="form.remarks"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog(0)">放弃更改</el-button>
          <el-button type="primary" @click="closeDialog(1)">
            提交更改
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import { useStore } from "vuex";
import link from "@/api/link.js";
import apiUrl from "@/api/url.js";
import { ElLoading } from "element-plus";
let store = useStore();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const fullscreenLoading = ref(false);
const closeDialog = (num: number) => {
  store.commit("DIALOG");
  if (num === 1) {
    let datas = {
      plate: form.plate,
      name: form.name,
      residence: form.residence,
      brand: form.brand,
      model: form.model,
      number: form.number,
      purchase: form.purchase,
      remarks: form.remarks,
    };
    link(
      apiUrl.HouseholdVehicles + "/" + store.state.HomeModule.uplistData.id,
      "PUT",
      datas
    ).then((resolve) => {
      return;
    });
    const loading = ElLoading.service({
      lock: true,
      text: "正在提交更改",
      background: "rgba(0, 0, 0, 0.7)",
    });
    setTimeout(() => {
      loading.close();
    }, 2000);
  } else {
    return;
  }
};
const formLabelWidth = "200px";

const form = reactive({
  plate: store.state.HomeModule.uplistData.plate,
  name: store.state.HomeModule.uplistData.name,
  residence: store.state.HomeModule.uplistData.residence,
  brand: store.state.HomeModule.uplistData.brand,
  model: store.state.HomeModule.uplistData.model,
  number: store.state.HomeModule.uplistData.number,
  purchase: store.state.HomeModule.uplistData.purchase,
  remarks: apiUrl.HouseholdVehicles.id,
});
</script>
<style scoped>
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
